package com.bdqn.boot.yuanshen.service.impl;

import com.bdqn.boot.yuanshen.bean.UserBehavior;
import com.bdqn.boot.yuanshen.mapper.UserBehaviorMapper;
import com.bdqn.boot.yuanshen.service.UserBehaviorService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserBehaviorServiceImpl implements UserBehaviorService {

    @Autowired
    private UserBehaviorMapper userBehaviorMapper;

    @Override
    public PageInfo<UserBehavior> getUserBehaviorByUserId(Integer userId, int pageNum, int pageSize) {
        // 开启分页功能
        PageHelper.startPage(pageNum, pageSize);
        List<UserBehavior> usersList = userBehaviorMapper.selectByUserId(userId);
        return new PageInfo<>(usersList);
    }

    @Override
    public PageInfo<UserBehavior> getUserBehaviorByVideoId(Integer videoId, int pageNum, int pageSize) {
        // 开启分页功能
        PageHelper.startPage(pageNum, pageSize);
        List<UserBehavior> usersList = userBehaviorMapper.selectByVideoId(videoId);
        return new PageInfo<>(usersList);
    }

    @Override
    public void addUserBehavior(UserBehavior userBehavior) {
        userBehaviorMapper.insertUserBehavior(userBehavior);
    }

    @Override
    public PageInfo<UserBehavior> getAllUserBehaviors(int pageNum, int pageSize) {
        // 开启分页功能
        PageHelper.startPage(pageNum, pageSize);
        List<UserBehavior> usersList = userBehaviorMapper.selectAll();
        return new PageInfo<>(usersList);

    }


}